package com.cacho.s2b.lesson.assertion;

import org.junit.Assert;

/**
 * @Description 断言封装
 * @Author LingWei
 * @date 2023/12/31
 **/
public class Assertion {
    // 失败时断言
    public static void fail(String msg){Assert.fail();}
    // 断言两个 int 类型相等
    public static void assertEquals(int actual,int expected,String msg){
        Assert.assertEquals(msg,actual,expected); // msg必须在前
    }
    public static void assertEquals(String actual,String expected,String msg){
        Assert.assertEquals(msg,actual,expected); // msg必须在前
    }
    public static void assertNotEquals(Object actual,Object expected,String msg){
        Assert.assertNotEquals(msg,actual,expected); // msg必须在前
    }
    public static void assertContains(String actual,String expected,String msg){
        if(!actual.contains(expected)&&!expected.contains(actual)){
            Assert.fail("实际结果-->"+actual +"没有包含逾期结果-->"+expected);
        }
    }
    public static void assertSameResult(String actual,String expected,String msg){
        boolean sameResult = Assertion.isSameNoFail(actual,expected);
        if (!sameResult){
            Assert.fail("期望值为："+expected+"但是实际值为："+actual);
        }
    }
    public static boolean isSameNoFail(String compare1, String compare2){
        boolean sameResult;
        sameResult = compare1.equals(compare2);
        return sameResult;
    }
}
